package com.example.weibo_app.controller;

import com.example.weibo_app.common.utils.AjaxResult;
import com.example.weibo_app.domain.Comment;
import com.example.weibo_app.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import java.util.List;

@RestController
@Api(tags = "文章评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/comments")
    @ApiOperation(value = "添加评论")
    public AjaxResult addComment(@RequestBody Comment comment) {
        return AjaxResult.success(commentService.addComment(comment));
    }

    @GetMapping("/comments/article/{articleId}")
    @ApiOperation(value = "查询某篇文章的所有评论")
    public AjaxResult getCommentsByArticleId(@PathVariable @Min(1) int articleId) {
        return AjaxResult.success(commentService.getCommentsByArticleId(articleId));
    }

    @GetMapping("/comments/user/{userId}")
    @ApiOperation(value = "查询某个用户的所有评论")
    public AjaxResult getCommentsByUserId(@PathVariable @Min(1) int userId) {
        return AjaxResult.success(commentService.getCommentsByUserId(userId));
    }

}
